﻿// 管理用户基本信息.
$(document).ready(function() {
     $.post("CheckRole.aspx",function(data){
            if(data=="2"){
                window.location.href="changepassword.htm";
            }
        });
    //给表单赋值.
    $.getJSON("GetUserInfo.aspx?format=json&jsoncallback=?",
        function(data){
        if(data.success){
            $("#LegalPerson").val(data.LegalPerson);
            $("#FlowMoney").val(data.FlowMoney);
            $("#WebSite").val(data.WebSite);
            $("#Address").val(data.Address);
            $("#Email").val(data.Email);
            $("#LinkMan").val(data.LinkMan);
            $("#Tel").val(data.Tel);
            $("#Postcode").val(data.Postcode);
            var competency = new Array();
            competency = data.Competency.split(",");
            var level = new Array();
            level = data.CompetencyLevel.split(",");
            
            $("input[name='Competency']").val(competency);
            
            for(j=0;j<=competency.length;j++)
            {   
                $("input[name='Competency']").each(function(i){
                    if($(this).attr("value")==competency[j]){
                       // alert(competency[j]+level[j] + i);
                        $("#Competency-"+(i+1)).val(level[j]).show();
                        
                    }
                })
            }
        }else{
            window.location.href="/login.htm";
        }
    });
    $("#Competency1").click(function(){
        if(this.checked){
          $("#Competency-1").show();
        }else{
            $("#Competency-1").val("");
            $("#Competency-1").hide();
            
        }  
    });
    $("#Competency2").click(function(){
        if(this.checked){
          $("#Competency-2").show();
        }else{
            $("#Competency-2").val("");
            $("#Competency-2").hide();
            
        }  
    });
    $("#Competency3").click(function(){
        if(this.checked){
          $("#Competency-3").show();
        }else{
            $("#Competency-3").val("");
            $("#Competency-3").hide();
            
        }  
    });
    $("#Competency4").click(function(){
        if(this.checked){
          $("#Competency-4").show();
        }else{
            $("#Competency-4").val("");
            $("#Competency-4").hide();
            
        }  
    });
    $("#Competency5").click(function(){
        if(this.checked){
          $("#Competency-5").show();
        }else{
            $("#Competency-5").val("");
            $("#Competency-5").hide();
            
        }  
    });
    $("#btnSubmit").click(function(){
        var msg = "";
        var password = $("#Password").val();
        if(password==""){
            msg +="<li>你的密码 未填写。</li>" ;
        }
        var legalperson = $("#LegalPerson").val();
        if(legalperson==""){
            $("#LegalPerson").prev().css("color","red").css("font-weight","bold");
            msg +="<li>企业法定代表人 未填写。</li>" ;
        }else{
           $("#LegalPerson").prev().css("color","#000000").css("font-weight","normal"); 
        }
        
        var flowmoney  =$("#FlowMoney").val();
        if(flowmoney==""){
            $("#FlowMoney").prev().css("color","red").css("font-weight","bold");
            msg +="<li>注册资金 未填写。</li>" ;
        }else{
            $("#FlowMoney").prev().css("color","#000000").css("font-weight","normal");
        }
        
        var address = $("#Address").val();
        if(address ==""){
            $("#Address").prev().css("color","red").css("font-weight","bold");
            msg +="<li>通讯地址 未填写。</li>" ;
        }else{
            $("#Address").prev().css("color","#000000").css("font-weight","normal");
        }
        
        var postcode = $("#Postcode").val();
        if(postcode ==""){
            $("#Postcode").prev().css("color","red").css("font-weight","bold");
            msg +="<li>邮政编码 未填写。</li>" ;
        }else{
           $("#Postcode").prev().css("color","#000000").css("font-weight","normal"); 
        }
        
        var linkman =$("#LinkMan").val();
        if(linkman ==""){
           $("#LinkMan").prev().css("color","red").css("font-weight","bold");
           msg +="<li>联系人 未填写。</li>" ; 
        }else{
           $("#LinkMan").prev().css("color","#000000").css("font-weight","normal"); 
        }
        
        var tel = $("#Tel").val();
        if(tel==""){
            $("#Tel").prev().css("color","red").css("font-weight","bold");
           msg +="<li>联系电话 未填写。</li>" ; 
        }else{
             $("#Tel").prev().css("color","#000000").css("font-weight","normal");
        }
        
        if($("#Competency1").attr("checked")){
            if($("select#Competency-1 option:selected").val()==""){
                msg +="<li>中央投资项目招标代理资质等级 未选择。</li>" ;
            }
        }
        if($("#Competency2").attr("checked")){
            if($("select#Competency-2 option:selected").val()==""){
                msg +="<li>工程类招标代理资质等级 未选择。</li>" ;
            }
        }
        if($("#Competency3").attr("checked")){
            if($("select#Competency-3 option:selected").val()==""){
                msg +="<li>机电产品国际招标代理资质等级 未选择。</li>" ;
            }
        }
        if($("#Competency4").attr("checked")){
            if($("select#Competency-4 option:selected").val()==""){
                msg +="<li>政府采购招标代理资质等级 未选择。</li>" ;
            }
        }
        if($("#Competency5").attr("checked")){
            if($("#Competency-5").val()==""){
                msg +="<li>其他招标代理资质等级 未填写。</li>" ;
            }
        }
        
        if(msg!=""){
            msg="<h2>以下表单项填写不正确，请检查：</h2><ol>" + msg +"</ol>";
            $(".msg-list").html(msg);
            $(".error-mess").show("fast");
        }
        else
        {
            $(".msg-list").html("");
            $(".error-mess").hide(); 
            //清空表单
//            $(":text").val("");
//            $("input[name='Competency']").each(function(){$(this).attr("checked",false);});
//            $("select").val("").hide();
            var website = $("#WebSite").val();
            var email = $("#Email").val();
            var compentcy = "";
            var compentcylevel = "";
            var centralevel ="";
            $("input[name='Competency']").each(function(i){
                if($(this).attr("checked")){
                    compentcy += $(this).attr("value")+",";
                    compentcylevel += $("#Competency-"+(i+1)).val()+",";
                    if($(this).attr("value")=="中央投资项目招标代理资质"){
                        centralevel = $("#Competency-"+(i+1)).val();
                    }
                }
            });
            
             $.post("UpdateCompanyInfo.aspx", {password:password,legalperson:legalperson,flowmoney:flowmoney,address:address,postcode:postcode,
                                        linkman:linkman,tel:tel,website:website,email:email,compentcy:compentcy,compentcylevel:compentcylevel,centralevel:centralevel
                                     },
               function(data){
                 alert(data);
                 
                 $("#Password").val("");
                 
           });

        }
        
    });
});

//<h2>以下表单项填写不正确，请检查：</h2><ol></ol>